#ifndef ITEMREFERENCE_H
#define ITEMREFERENCE_H


#include "models_global.h"
#include "Item.h"


#include <QThread>
#include <QSharedData>
#include <QSharedDataPointer>
#include <QPointer>

//class ItemReferenceFinder;


class MODELSSHARED_EXPORT ItemReference : public Item
{
    Q_OBJECT

    class Data : public QSharedData
    {
    public:
        Data() {}
        Data(const Data& other) : QSharedData(other)
        {
            refItem = other.refItem;
            refName = other.refName;
            refType = other.refType;
        }

        QPointer<AbstractItem>  refItem;
        QString                 refName;
        QVariant                refType;
    };

public:

    enum DataType
    {
        DataType_FIRST = Item::DataType_LAST + 1,

        ReferenceData = DataType_FIRST,
        TypeData,

        DataType_LAST = TypeData
    };

    enum ReferenceType
    {
        ReferenceType_FIRST = 0,

        BonusRef = ReferenceType_FIRST, // normal reference...
        SynergyRef,   // grant additional bonus if synergy is found
        GroupRef,     // references to all items in a group
        RequirementRef, // requires referenced item (with minimum value if any)

        ReferenceType_LAST = RequirementRef
    };

    ItemReference(AbstractItem *parent);
    virtual ~ItemReference();

    static QString typeName(const int& ref_type);

    bool isValid() const;


    virtual int fieldCount() const;
    virtual QString fieldName(const int &data_type) const;
    virtual int field(const QString &field_name) const;

    QString referencedName() const;
    AbstractItem* referencedItem() const;


public slots:

    void onRefreshReferenceItem();
    void onReferenceItemDirty();


protected:


    virtual QVariant customData(const int &data_type, int role = Qt::DisplayRole) const;
    virtual void setCustomData(const int &data_type, const QVariant &value);


private:

    QSharedDataPointer<Data> d;


};

#endif // ITEMREFERENCE_H
